import os  # 导入os模块

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')  # 设置环境变量，指定Django的settings模块

from django.conf import settings  # 从django.conf模块导入settings对象
from celery import platforms  # 从celery模块导入platforms对象

# 租户模式
if "django_tenants" in settings.INSTALLED_APPS:  # 如果'django_tenants'在INSTALLED_APPS中
    from tenant_schemas_celery.app import CeleryApp as TenantAwareCeleryApp  # 从tenant_schemas_celery.app模块导入TenantAwareCeleryApp类

    app = TenantAwareCeleryApp()  # 创建一个TenantAwareCeleryApp实例
else:
    from celery import Celery  # 从celery模块导入Celery类

    app = Celery(f"application")  # 创建一个Celery实例，命名为application

app.config_from_object('django.conf:settings')  # 从django.conf模块的settings对象加载配置
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)  # 自动发现任务
platforms.C_FORCE_ROOT = True  # 设置C_FORCE_ROOT为True
